/**
 * 哈希函数，将key映射成index
 * @param str 转换的key
 * @param max 数组的长度（最大的数值）
 * @returns 索引值
 */
function hashFunction(str: string, max: number, BaseNum = 27): number {
  //计算hashCode cats==>60337(27为底的时候)
  let hashCode = 0;
  const length = str.length;

  for (let i = 0; i < length; i++) {
    hashCode = BaseNum * hashCode + str.charCodeAt(i);
  }

  const index = hashCode % max;

  return index;
}

console.log(hashFunction("aaa", 7));
console.log(hashFunction("bbb", 7));
console.log(hashFunction("ccc", 7));
console.log(hashFunction("ddd", 7));
console.log(hashFunction("eee", 7));
console.log(hashFunction("abc", 7));

export {};
